Embodiments of the present invention relate generally to methods and systems for debugging or troubleshooting a computer program and more particularly to detecting a memory leak caused by an application.
Memory leaks are a common problem that occurs because of errors in software code. It can be described as a problem of the software program being unable to reuse the memory that it does not need anymore. A typical case is that the software error prevents the memory the program has previously obtained from the memory manager and does not need anymore, from being returned to the memory manager. For example, an application may allocate memory for a particular object, data structure, etc. but then, due to an error, fail to deallocate this memory. Over time, with many iterations of the application, such errors can create a growth in the size of a memory heap used by the application and, correspondingly, a decrease in the memory available for use by the application.
In order to identify and correct these errors, a memory leak analysis can be performed on an application, for example during debugging or troubleshooting of the application. Existing tools for performing memory leak analysis, so called memory profilers, allow for monitoring of the memory to help find the objects that grow, and locate the referrers of those objects. Then, determining the failing code path related to these objects is done manually. Typically, the memory profile collects a heap dump, i.e., takes a snapshot of the memory used by an application at a particular instant in time. Several memory profiler software tools exist on the market which simplify the task by analyzing a heap dump where it is possible to inspect the references between the objects that existed in memory at the time of collection of the heap dump. Certain algorithms exist for automating such a heap analysis. For example, some tools can compare two heap dumps to find the differences, which can then be attributed to memory leaks. The investigation of the memory leak would then normally start with the area of memory that can be seen accumulating the most objects.
The drawbacks of either of this analysis stem from an inability to monitor the heap at run time, so that only one or two heap dumps corresponding to two points in the program's life, can be analyzed. This often provides false positives—some areas are determined to be growing, whereas the growth can be proven to be transient. With the size of memory being in hundreds of megabytes and the program constantly allocating and deallocating memory during its operation, this becomes a very difficult task for a human, especially when monitoring live running programs. Additionally, the memory leak is rarely caused by a single software problem; there usually is a superposition of problems that cause the memory leak to occur. This complicates manual analysis even further. Hence, there is a need for improved methods and systems for detecting and analyzing memory leaks.